package com.example.liwushuo;

import com.example.liwushuo.urls.urls;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.widget.Toast;

public class HomeListItemActivity extends Activity {

	private WebView web;
	private long id;
	private String url;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_home_list_item);
		id = getIntent().getLongExtra("id", -1);
		if (id != -1) {
			url = urls.getItemUrl + id;
			Log.i("url", "------" + url);
		}

		web = (WebView) findViewById(R.id.home_list_webView);

		loadData();

	}

	private void loadData() {
		if (url != null) {
			BaseApp.getHttpUtils().send(HttpMethod.GET, url,
					new RequestCallBack<String>() {

						@Override
						public void onFailure(HttpException arg0, String arg1) {

							BaseApp.getToast("网络连接错误，请检查网络连接");

						}

						@Override
						public void onSuccess(ResponseInfo<String> response) {
							Log.i("web", "-------------这里执行了");

							web.loadData(response.result,
									"text/html;charset=utf-8", "utf-8");
						}
					});
		}
	}
}
